<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:composite="http://java.sun.com/jsf/composite">

    <h:head>
        <f:facet name="first">
            <meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
        </f:facet>
    </h:head>

    <composite:interface>
        <composite:attribute name="lblbtnfind" type="java.lang.String" />
        <composite:attribute name="inNroOrden" type="java.lang.String" />
        <composite:attribute name="idInputNroOrden" type="java.lang.String" />
        <composite:attribute name="update" type="java.lang.String" />
    </composite:interface>

    <composite:implementation>
        <p:messages id="msgs" showDetail="false"  autoUpdate="true" closable="true" globalOnly="true"/>
        <p:outputPanel>
            <p:commandButton id="btnFindOrden" value="#{cc.attrs.lblbtnfind}"
                             image="icon-add-btn" immediate="true" update="cbxTipoOrden,datatblOrdenes" process="@this #{cc.attrs.idInputNroOrden}"
                             actionListener="#{MBCompFindOrden.cargarCombo(cc.attrs.inNroOrden)}" ajax="true"
                             oncomplete="wv#{cc.id}.show()" style="font-size:10px;">
            </p:commandButton>	
        </p:outputPanel>

        <p:dialog id="idFindOrden" header="Buscando Orden" showEffect="explode"
                  widgetVar="wv#{cc.id}" modal="true" maximizable="true">
            <p:panelGrid id="pnlFindOrden" style="width:100%;text-align:left">-->
                <p:row>
                    <p:column>
                        <h:outputLabel id="lblTipoOrden" value="TIPO DE ORDEN(*): " class="lblForm" />
                    </p:column>
                    <p:column>
                        <p:selectOneMenu id="cbxTipoOrden" 
                                         value="#{BKCompFindOrden.idTipoOrdenFind}">
                            <f:selectItem itemLabel="Seleccione" itemValue="" />
                            <f:selectItems value="#{BKCompFindOrden.listarTipoOrden}"
                                           var="tipo" itemLabel="#{tipo.desParametroDet}"
                                           itemValue="#{tipo.valCadena}" />
                            <p:ajax event="change" listener="#{MBCompFindOrden.storeOrdenCSPorTipo}" update="cbxNroOrdenCS" rendered="false"/>
                        </p:selectOneMenu>
                    </p:column>
                    <p:column>
                        <p:commandButton id="btnFindLoc" value="Buscar Ordenes" 
                                         ajax="true" update="datatblOrdenes" process="@this cbxTipoOrden cbxNroOrdenCS" 
                                         actionListener="#{MBCompFindOrden.buscarOrdenCS}"/>
                    </p:column>
                </p:row>
                <p:row rendered="false">
                    <p:column>
                        <h:outputLabel id="lblNroOrden" value="Nº DE ORDEN: " class="lblForm" />
                    </p:column>
                    <p:column colspan="2">
                        <p:autoComplete value="#{BKCompFindOrden.nroOrdenCSCurrent}"
                                        completeMethod="#{MBCompFindOrden.buscarNroOrdenCS}"
                                        id="cbxNroOrdenCS"  dropdown="true"
                                        forceSelection="true">
                        </p:autoComplete>
                    </p:column>
                </p:row>
                <p:row>
                    <p:column colspan="3">
                        <p:fieldset legend="Lista de Ordenes">
                            <p:dataTable id="datatblOrdenes" var="det"
                                         value="#{BKCompFindOrden.listaOrdenCompraOrServicio}"
                                         emptyMessage="No exsiten ordenes de compra o servicio" filteredValue=""
                                         rowIndexVar="rowIndex" paginator="true" rows="10"
                                         paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink}
                                         {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                                         rowsPerPageTemplate="5,10,15"  rowKey="#{det.id}"  
                                         selection="#{BKCompFindOrden.ordenCSCurrent}" selectionMode="single">

                                <p:ajax event="rowSelect"/>

                                <p:column id="idColumnaNum" style="width: 5%" headerText="Num.">
                                    <h:outputText value="#{rowIndex+1}" />
                                </p:column>

                                <p:column id="idColumnaCodigo" style="width: 25%"
                                          sortBy="#{det.codigo}" 
                                          headerText="Nro Orden">
                                    <h:outputText value="#{det.codigo}" />
                                </p:column>

                                <p:column id="idColumnaTipo" style="width: 25%"
                                          sortBy="#{det.descTipoOrden}" headerText="Tipo">
                                    <h:outputText value="#{det.descTipoOrden}" />
                                </p:column>

                            </p:dataTable>
                        </p:fieldset>
                    </p:column>
                </p:row>
                <p:row>
                    <p:column style="text-align:center" colspan="3">
                        <p:commandButton id="btnAceptarOCS" value="Aceptar"
                                         immediate="true" process="@this" update="#{cc.attrs.update}" 
                                         actionListener="#{MBCompFindOrden.notificarObservadores}" 
                                         oncomplete="wv#{cc.id}.hide()" />
                        <p:commandButton id="btnCancelarOCS" value="Cancelar" type="button"
                                         onclick="wv#{cc.id}.hide()" />
                    </p:column>
                </p:row>
            </p:panelGrid>
        </p:dialog>

    </composite:implementation>

</html>